package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.ManageSerivce;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/product")
public class SkuManageController {
    @Autowired
    private ManageSerivce manageSerivce;
    /**
     *
     *保存sku
     * http://api.gmall.com/admin/product/saveSkuInfo
     */
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        manageSerivce.saveSkuInfo(skuInfo);
        return Result.ok();
    }
    /**
     *
     *sku  分页列表
     * http://api.gmall.com/admin/product/list/{page}/{limit}
     */
    @GetMapping("list/{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit){
        Page<SkuInfo> skuInfoPage = new Page<>(page, limit);
        IPage<SkuInfo> iPage = manageSerivce.getPage(skuInfoPage);
        return Result.ok(iPage);
    }
    /**
     * 上架商品
     * http://api.gmall.com/admin/product/onSale/43
     */
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        manageSerivce.onSale(skuId);
        return Result.ok();
    }
    /**
     * 下架商品
     * http://api.gmall.com/admin/product/cancelSale/39
     */
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
        manageSerivce.cancelSale(skuId);
        return Result.ok();
    }
}
